<%--
 * (c)2010-2013 Andrea Caltroni (andrea.caltroni@pd.infn.it), INFN (www.infn.it)
 *
 * This file is part of the IGI Survey Portlet (from here on shortened to IGISP).
 * IGISP is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the Free 
 * Software Foundation, either version 3 of the License, or (at your option) any 
 * later version.
 *
 * IGISP is distributed in the hope that it will be useful, but WITHOUT ANY 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IGISP. If not, see <http://www.gnu.org/licenses/>.
 *
--%>

<%@ include file="./init.jsp"%>

<c:set var="numAnswers" value="${fn:length(answers)}" />

<h3><spring:message code="survey.label.survey" />: ${userChoice.question.survey.name}</h3>
<table class="lfr-table">
    <tr>
        <td><spring:message code="survey.label.question" /> ${questionIdxs[userChoice.question.position]}/${fn:length(questionIdxs)}
[<fmt:formatNumber type="number"
    value="${(questionIdxs[userChoice.question.position] / fn:length(questionIdxs)) * 100}"
    maxFractionDigits="2" />%]:</td>
    </tr>
    <tr>
        <th>${userChoice.question.description}</th>
    </tr>
</table>
<%--
<h4><spring:message code="survey.label.question" /> ${questionIdxs[userChoice.question.position]}/${fn:length(questionIdxs)}
[<fmt:formatNumber type="number"
	value="${(questionIdxs[userChoice.question.position] / fn:length(questionIdxs)) * 100}"
	maxFractionDigits="2" />%]</h4>
<h4>${userChoice.question.description}</h4>
 --%>
<div class="portlet-body">
    <portlet:actionURL var="userChoiceActionUrl">
	    <portlet:param name="action" value="submitUserChoice" />
    </portlet:actionURL> 
    
	<form:form name="answerQuestionForm" commandName="userChoice"
		method="post" action="${userChoiceActionUrl}">
	
		<div><form:errors cssClass="portlet-msg-error" path="*" /></div>
	
		<div class="lfr-separator">&nbsp;</div>
	
		<c:choose>
			<c:when test="${!answered}">
	
				<c:choose>
					<c:when test="${numAnswers > 0}">

						<c:choose>
							<c:when test="${userChoice.question.answersType == 'SINGLE_CHOICE'}">
								<%@ include file="singleUserAnswer-inc.jsp"%>
							</c:when>
                            <c:when test="${userChoice.question.answersType == 'MULTIPLE_CHOICE'}">
                                <%@ include file="multipleUserAnswer-inc.jsp"%>
                            </c:when>
                            <c:when test="${userChoice.question.answersType == 'SINGLE_ANSWER'}">
                                <%@ include file="singleAnswer-inc.jsp"%>
                            </c:when>
							<c:otherwise>
								<spring:message code="userChoice.question.invalidAnswersType" />
							</c:otherwise>
						</c:choose>

					</c:when>
					<c:otherwise>
						<spring:message code="userChoice.question.noAnswers" />
					</c:otherwise>
				</c:choose>
	
			</c:when>
			<c:otherwise>
				<spring:message code="message.question.alreadyAnswered" />
			</c:otherwise>
		</c:choose>
	
		<div class="lfr-separator">&nbsp;</div>
	
        <c:if test="${numAnswers > 0 && !answered}">
			<input type="submit" value="<spring:message code="button.save"/>" />
        </c:if>
        <c:if test="${numAnswers > 0 && answered}">
            <input type="submit" name="_skip"
                value="<spring:message code="button.next"/>" />
        </c:if>
        <c:if test="${numAnswers > 0 && !answered && !skipToQuestionPresent}">
		    <input type="submit" name="_skip"
			    value="<spring:message code="button.skip"/>" />
        </c:if>
	
	</form:form>
</div>

<div class="lfr-separator">&nbsp;</div>

<div class="portlet-section-footer">
    <a href="<portlet:renderURL portletMode="view"/>"> <img title="<spring:message code="button.home"/>" src="<html:imagesPath/>home.png" border=0 /> </a>
</div>
